import React, { useEffect, useState } from 'react'
import styles from "../assets/styles/list.module.less"
import actions from "../qiankun/actions"

export default function List() {
  const [myname,setMyname] = useState("默认名字")
  //组件挂载成功
  useEffect(()=>{
    actions.onGlobalStateChange((state,prev)=>{
      console.log("更新过后数据",state);
      console.log("更新之前数据",prev);
      setMyname(state.username)
    })
  },[])

  const changeState = ()=>{
    actions.setGlobalState({username:"蜗牛学苑"})
  }

  return (
    <div>
      <h2 className={styles.title}>List</h2>
      <p>{myname}</p>
      <button onClick={changeState}>修改名字</button>
      <h3 className='commonColor'>React子应用文本</h3>
      <h2 className="myMenu">React测试文本</h2>
    </div>
  )
}
